﻿using MES.Desktop.Common;
using MES.Desktop.IService;
using Prism.Mvvm;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES.Desktop.SystemModule.Models
{
    public class UserModel : DataModelBase
    {
        public UserModel() { }

        IUserService _userService;
        public UserModel(IUserService userService)
        {
            _userService = userService;
        }

        public int Index { get; set; }

        public int UserId { get; set; }

        private string _userName;

        public string UserName
        {
            get { return _userName; }
            set
            {
                _userName = value;

                this.ClearErrors();
                if (string.IsNullOrEmpty(value))
                {
                    this.RaiseErrors("用户名不能为空");
                }
                if (_userService != null && _userService.CheckUserName(value, this.UserId))
                {
                    this.RaiseErrors("用户名已被占用");
                }
            }
        }

        public string RealName { get; set; }
        private string _userIcon;

        public string UserIcon
        {
            get { return _userIcon; }
            set { SetProperty<string>(ref _userIcon, value); }
        }

        public int? Age { get; set; }
        private int? _gender;
        public int? Gender
        {
            get { return _gender; }
            set { SetProperty<int?>(ref _gender, value); }
        }

        public string Address { get; set; }

        public string Password { get; set; }
        public string Email { get; set; }
        private string _phone;

        public string Phone
        {
            get { return _phone; }
            set
            {
                SetProperty<string>(ref _phone, value);

                this.ClearErrors();
                if (string.IsNullOrEmpty(value))
                {
                    this.RaiseErrors("手机号不能为空");
                }
            }
        }


        private int _status;

        public int Status
        {
            get { return _status; }
            set
            {
                SetProperty<int>(ref _status, value);
                if (value == 1) LockButtonText = "锁定";
                else if (value == 0) LockButtonText = "启用";
            }
        }

        private bool _isSelected;

        public bool IsSelected
        {
            get { return _isSelected; }
            set { SetProperty<bool>(ref _isSelected, value); }
        }

        public int DepartId { get; set; }
        public string DepartName { get; set; }
        public int PostId { get; set; }
        public string PostName { get; set; }

        public List<RoleModel> Roles { get; set; }

        private string _lockButtonText;

        public string LockButtonText
        {
            get { return _lockButtonText; }
            set { SetProperty<string>(ref _lockButtonText, value); }
        }

    }
}
